home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig05_11.jar / Ch05 / Fig05_11 / Fig05_11.cpp next >
C/C++ Source or Header  |  1997-10-14  |  649b  |  27 lines

  1. // Fig. 5.11: fig05_11.cpp
  2. // Printing a string one character at a time using
  3. // a non-constant pointer to constant data
  4. #include <iostream.h>
  5.  
  6. void printCharacters( const char * );
  7.  
  8. int main()
  9. {
  10.    char string[] = "print characters of a string";
  11.  
  12.    cout << "The string is:\n";
  13.    printCharacters( string );
  14.    cout << endl;
  15.    return 0;
  16. }
  17.  
  18. // In printCharacters, sPtr is a pointer to a character 
  19. // constant. Characters cannot be modified through sPtr 
  20. // (i.e., sPtr is a "read-only" pointer).
  21. void printCharacters( const char *sPtr )
  22. {
  23.    for ( ; *sPtr != '\0'; sPtr++ )   // no initialization
  24.       cout << *sPtr;
  25. }
  26.  
  27.